package creational_pattern.builder_pattern;

public class BuilderPattern {
    public static void main(String[] args) {
        Builder builder = new ConcreteBuilder();
        Diector diector = new Diector(builder);
        Product construct = diector.construct();
        System.out.println(construct);
    }
}

abstract class Builder{
    protected Product product = new Product();
    abstract void buildPartA();

    abstract void buildPartB();

    abstract  void buildPartC();

    Product getResult(){
        return product;
    }

}
class ConcreteBuilder extends Builder{

    @Override
    public void buildPartA() {
        this.product.setName("aaa");
        System.out.println("build A");
    }

    @Override
    public void buildPartB() {
        this.product.setName("bbb");
        System.out.println("build B");
    }

    @Override
    public void buildPartC() {
        this.product.setName("ccc");
        System.out.println("build C");
    }

}
class Product{
    @Override
    public String toString() {
        return "Product{" +
                "name='" + name + '\'' +
                '}';
    }

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
class Diector {
    private Builder builder;

    public void setBuilder(Builder builder) {
        this.builder = builder;
    }

    public Diector(Builder builder) {

        this.builder = builder;
    }

    public Product construct(){
        builder.buildPartA();
        builder.buildPartC();
        return builder.getResult();
    }
}